package Ms.controller;
import Result.Result;
import cn.dev33.satoken.annotation.SaCheckPermission;
import Ms.entity.User;
import Ms.entity.enums.UserStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import Ms.service.UserService;
import Ms.utils.PasswordUtil;

// UserAdminController.java
@RestController
@RequestMapping("/admin/users")
public class UserAdminController {

    @Autowired
    UserService userService ;

    @SaCheckPermission("user:manage")
    @PostMapping("/lock/{userId}")
    public Result lockUser(@PathVariable Long userId) {
        User user = userService.getUserById(userId);
        user.setStatus(UserStatus.LOCKED);
        return userService.updateById(user) ?
                Result.success() : Result.error("操作失败");
    }

    @SaCheckPermission("user:reset")
    @PostMapping("/reset-pwd/{userId}")
    public Result resetPassword(@PathVariable Long userId) {
        String newPwd = PasswordUtil.generateTempPassword();
        userService.updatePassword(userId, newPwd);
        // 发送邮件通知用户------------------------------------------------
//        emailService.sendPwdResetEmail(userId, newPwd);
        return Result.success();
    }
}